package com.zhentao.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.zhentao.kafka.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/hello")
    public String hello(){
        kafkaTemplate.send("tokper","程序员");
        return "ok";
    }
    @GetMapping("/hello1")
    public String hello1(){
        User user=new User();
        user.setUsername("1111111");
        user.setAge(111);
        kafkaTemplate.send("tokper1", JSON.toJSONString(user));
        return "ok";
    }

    Integer a;
    @GetMapping("/test11")
    public String test11(String aa){
        kafkaTemplate.send("itcast",aa);
        a++;
        return a.toString();
    }
}
